import axios from 'axios'
import type { ApiResponse, CityInfo, RateInfo } from '@/types/api'
import { mockCities, mockRates } from './mock'

// 获取城市列表
export const getCityList = async (): Promise<CityInfo[]> => {
  // 使用 Mock 数据
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(mockCities)
    }, 300) // 模拟网络延迟
  })
}

// 获取城市利率信息
export const getCityRate = async (cityCode: string): Promise<RateInfo> => {
  // 使用 Mock 数据
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const rate = mockRates[cityCode]
      if (rate) {
        resolve({
          cityCode,
          ...rate,
          updateTime: new Date().toISOString()
        })
      } else {
        reject(new Error('未找到该城市的利率信息'))
      }
    }, 300)
  })
}

// 如果后续要对接真实接口，可以使用以下代码：
/*
const baseURL = import.meta.env.VITE_API_URL

// 创建 axios 实例
const api = axios.create({
  baseURL,
  timeout: 10000
})

export const getCityList = async (): Promise<CityInfo[]> => {
  const response = await api.get<ApiResponse<CityInfo[]>>('/cities')
  return response.data.data
}

export const getCityRate = async (cityCode: string): Promise<RateInfo> => {
  const response = await api.get<ApiResponse<RateInfo>>(`/rates/${cityCode}`)
  return response.data.data
}
*/ 